package com.hl.payServer.util;


import tk.mybatis.mapper.util.StringUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 日期工具类
 */
public class DateUtil {
	//showType 的取值：例如“yyyy年MM月dd日hh时mm分ss秒”，“yyyy-MM-dd HH:mm:ss” 等
	public static Calendar cal = new GregorianCalendar(); 
	public static int YEAR = cal.get(Calendar.YEAR);
	public static int MONTH = cal.get(Calendar.MONTH)+1;
	public static int DAY_OF_MONTH = cal.get(Calendar.DAY_OF_MONTH);
	public static int DAY_OF_WEEK = cal.get(Calendar.DAY_OF_WEEK)-1;
	
	public static Date getNowTime(){
		return new Date();
	}
	
	//以showType的格式，返回String类型的当前时间
	public static String getNowTime(String showType){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat(showType);
		return sdf.format(date);
	}
	
	//将date按照showType转换成string
	public static String turnDateToString(Date dDate,String showType){
		DateFormat df = new SimpleDateFormat(showType);
		String dateString = df.format(dDate);
		return dateString;
	}
	
	//返回将string转换成date类型
	public static Date turnStringToDate(String sDate,String showType){
		//sDate的格式要和showType相符
		DateFormat df = new SimpleDateFormat(showType);
		Date date = null;
		try {
			date = df.parse(sDate);
		} catch (ParseException e) {
			df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			try {
				date =df.parse(sDate);
			} catch (ParseException e1) {
				df = new SimpleDateFormat("yyyy-MM-dd HH");
				try{
					date =df.parse(sDate);
				}catch(ParseException e2){
					df = new SimpleDateFormat("yyyy-MM-dd");
					try{
						date =df.parse(sDate);
					}catch(ParseException e3){
						System.out.println("格式不一致，返回null");
					}
				}
			}
		}
		return date;
	}
	
	//获得时间差
	public static boolean getTimeDifference(Long timeBegin,Long timeEnd,Long timeStanding){
		//大于指定时间返回true，否则返回false
		Long difference = timeEnd - timeBegin;
		if(difference>=timeStanding){
			return true;
		}else{
			return false;
		}
	}
	
	//计算两个日期相隔的天数  
    public static int getTimeDifference(Date firstDate,Date secondDate)   {  
    	if(firstDate==null || secondDate==null)
    		return 0;
        int nDay=(int)((firstDate.getTime()-secondDate.getTime())/(24*60*60*1000));  
        return nDay;  
    }
    
  //计算两个日期相隔的秒数  
    public static int getTimeDifferenceSencond(Date firstDate,Date secondDate)   {  
    	if(firstDate==null || secondDate==null)
    		return 0;
        int nDay=(int)((firstDate.getTime()-secondDate.getTime())/1000);  
        return nDay;  
    }
    
    /**
	 * 获取一年中的第几周
	 * 时间格式'yyyy-MM-dd'
	 * cuiqinglong create 2008-3-8
	 * @param sDate
	 * @return
	 */
	public static int getWeek(String sDate){
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day);
		int weekno=cal.get(Calendar.WEEK_OF_YEAR);
		return weekno;
	}
	
	/**
	 * 获取日期是星期几
	 * 时间格式'yyyy-MM-dd'
	 * cuiqinglong create 2008-3-8
	 * @param sDate
	 * @return
	 */
	public static String getWeekDay(String sDate){
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day);
		int weekDay=cal.get(Calendar.DAY_OF_WEEK);
		String result = null;
		switch (weekDay) {
		case 1:
			result = "周日";
			break;
		case 2:
			result = "周一";
			break;
		case 3:
			result = "周二";
			break;
		case 4:
			result = "周三";
			break;
		case 5:
			result = "周四";
			break;
		case 6:
			result = "周五";
			break;
		case 7:
			result = "周六";
			break;
		}
		return result;
	}
	
	
	/**
	 * 获取一年中的第几季度
	 * 时间格式'yyyy-MM-dd'
	 * cuiqinglong create 2008-3-8
	 * @param sDate
	 * @return
	 */
	public static int getQuarter(String sDate){
		int month = new Integer(sDate.substring(5,7));
		switch (month) {
		case 1:
			return 1;
		case 2:
			return 1;
		case 3:
			return 1;
		case 4:
			return 2;
		case 5:
			return 2;
		case 6:
			return 2;
		case 7:
			return 3;
		case 8:
			return 3;
		case 9:
			return 3;
		case 10:
			return 4;
		case 11:
			return 4;
		case 12:
			return 4;
		default:
			return 1;
		}
	}
	/**
	 * 获取半年，上半年0，下半年1
	 * 时间格式'yyyy-MM-dd'
	 * cuiqinglong create 2008-3-8
	 * @param sDate
	 * @return
	 */
	public static int getHYear(String sDate){
		int month = new Integer(sDate.substring(5,7));
		if(month>=1 && month<=6){
			return 0;
		}else{
			return 1;
		}
	}
	
	public static String getYesterday(String sDate,String type){
		if(sDate.equals("")){
			sDate=getNowTime(type);
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day-1);
		return DateUtil.turnDateToString(cal.getTime(),type);
	}
	
	public static String getYesterday(String sDate){
		return getYesterday(sDate, "yyyy-MM-dd");
	}
	
	public static Date getTomorrow(String sDate){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day+1);
		return cal.getTime();
	}
	
	public static String getOneWeekAgo(String sDate){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day-7);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd");
	}
	
	public static String getOneMonthAgo(String sDate){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month-1);
		cal.set(Calendar.DAY_OF_MONTH, day);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd");
	}
	
	public static String getOneYearAgo(String sDate){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year-1);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd");
	}
	
	public static String getMonthChange(Date date,int months,String format){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date == null ? new Date() : date);
		cal.add(Calendar.MONTH, months);
		return DateUtil.turnDateToString(cal.getTime(),format == null || format.equals("") ? "yyyy-MM-dd" : format);
	}
	
	public static String getSomeDaysAgo(String sDate,int days){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day-days);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd");
	}
	public static String getSomeDaysAfter(String sDate,int days){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd");
		}
		if(days==0)
			return sDate;
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day+days);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd");
	}
	public static String getSomeSecondsAgo(String sDate,int seconds){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd HH:mm:ss");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		int hour = new Integer(sDate.substring(11,13));
		int minute = new Integer(sDate.substring(14,16));
		int second = new Integer(sDate.substring(17,19));
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day);
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, minute);
		cal.set(Calendar.SECOND, second-seconds);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd HH:mm:ss");
	}
	public static String getSomeSecondsAfter(String sDate,int seconds){
		if(sDate.equals("")){
			sDate=getNowTime("yyyy-MM-dd HH:mm:ss");
		}
		int year = new Integer(sDate.substring(0,4));
		int month = new Integer(sDate.substring(5,7))-1;
		int day = new Integer(sDate.substring(8,10));
		int hour = new Integer(sDate.substring(11,13));
		int minute = new Integer(sDate.substring(14,16));
		int second = new Integer(sDate.substring(17,19));
		//logger.debug("year:"+year+" month:"+month+" day:"+day+" hour:"+hour+" minute:"+minute+" second:"+second);
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, day);
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, minute);
		cal.set(Calendar.SECOND, second+seconds);
		return DateUtil.turnDateToString(cal.getTime(),"yyyy-MM-dd HH:mm:ss");
	}
	
	//计算一个月有多少天
	public static int getMouthDayCounts(String yearmonth){
		String str[]=yearmonth.split("-");
		Calendar   cal   =   Calendar.getInstance();   
		cal.set(Calendar.YEAR,Integer.parseInt(str[0]));
		cal.set(Calendar.MONTH,Integer.parseInt(str[1])-1);//7月   
		int   maxDate   =   cal.getActualMaximum(Calendar.DATE);
		return maxDate;
	}
	public static List<Date> getMouthDayCount(String yearmonth){
		String str[]=yearmonth.split("-");
		Calendar   cal   =   Calendar.getInstance();   
		cal.set(Calendar.YEAR,Integer.parseInt(str[0]));
		cal.set(Calendar.MONTH,Integer.parseInt(str[1])-1);//7月   
		int   maxDate   =   cal.getActualMaximum(Calendar.DATE);
		List<Date> list=new ArrayList<Date>();
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(DateUtil.turnStringToDate(yearmonth + "-" + maxDate,"yyyy-MM-dd"));
	    calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+1);//让日期减1 2
	    list.add(DateUtil.turnStringToDate(yearmonth + "-01", "yyyy-MM-dd"));
		list.add(calendar.getTime());
		
		return list;
	}
	
	public static int getActualMaximum(String yearMonth) throws ParseException{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
		Date date = simpleDateFormat.parse(yearMonth);
		Calendar cal = Calendar.getInstance();   
		cal.setTime(date);
		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	
	public static String valiBatch(String value){
		//验证批次输入
		Integer year = Integer.parseInt(value.substring(0,4));
		Integer month = Integer.parseInt(value.substring(4,6));
		Integer day = Integer.parseInt(value.substring(6,8));
		Integer hour = Integer.parseInt(value.substring(8,10));
		Integer min = Integer.parseInt(value.substring(10,12));
		if(year<2000){
			return "格式不正确,年份必须为2000年之后";
		}
		if(month>12 || month<=0){
			return "格式不正确,月份必须是01-12的数字";
		}
		try{
			int maxDay = DateUtil.getActualMaximum(year.toString()+month);
			if(day>maxDay){
				return "格式不正确,"+month+"月最大天数:"+maxDay;
			}
		}catch (ParseException e) {
			return "格式不正确";
		}
		if(hour>23){
			return "格式不正确,小时必须是00-23的数字";
		}
		if(min>59){
			return "格式不正确,小时必须是00-59的数字";
		}
		return null;
	}
	
	public static Date getAfterDate(Date date,int days)   
	{   
	    Calendar calendar = Calendar.getInstance();      
	    calendar.setTime(date);   
	    calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) + days);   
	    return calendar.getTime();
	} 
	public static Date getBeforeDate(Date date,int days)   
	{   
	    Calendar calendar = Calendar.getInstance();      
	    calendar.setTime(date);   
	    calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) - days);   
	    return calendar.getTime();
	} 
	/**
	 * 把日期和时间组合成一个日期完整形式
	 * @param date   yyyy-MM-dd
	 * @param time   HH:mm:ss
	 * @return    拼接好的日期形式
	 *
	 */
	public static Date addDateAndTime(Date date,Date time){
		SimpleDateFormat sdfD = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdfT = new SimpleDateFormat("HH:mm:ss");
		DateFormat df =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String formatDate = sdfD.format(date);
		String formatTime = sdfT.format(time);
		try {
			Date parse = df.parse(formatDate+" "+formatTime);
			return parse;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	//把yyyymmdd转成yyyy-MM-dd hh:mm:ss格式
	public static String formatDatess(String str) {
		SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMddhhmmss");
		SimpleDateFormat sf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String sfstr = "";
		try {
			sfstr = sf2.format(sf1.parse(str));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sfstr;
	}
	//把yyyy-MM-dd hh:mm:ss转成yyyymmdd格式
	public static String formatDates(Date date) {
		SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMddHHmmss");
		String sfstr = "";
		try {
			sfstr = sf1.format(date);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sfstr;
	}
	/**
	 * 把日期和时间组合成一个日期完整形式
	 * @param date   yyyy-MM-dd
	 * @param time   HH:mm:ss
	 * @return    拼接好的日期形式
	 *
	 */
	public static Date addDateAndTimeString(String date,String time){
		DateFormat df =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
		try {
			Date parse = df.parse(date+" "+time);
			return parse;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 判断当前时间是否在某个时间范围内
	 * @param date
	 * @param startHours
	 * @param endHours
	 * @return
	 */
	public static boolean isBetween(Date date,String startHours,String endHours){
		Date startDate = DateUtil.turnStringToDate(startHours, "yyyy-MM-dd HH:mm:ss");
		Date endDate = DateUtil.turnStringToDate(endHours, "yyyy-MM-dd HH:mm:ss");
		if(date.getTime()>=startDate.getTime() && date.getTime()<=endDate.getTime()){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 判断当前时间是否在某个时间范围内
	 * @param date
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static boolean isBetween(Date date,Date startDate,Date endDate){
		if(date.getTime()>=startDate.getTime() && date.getTime()<=endDate.getTime()){
			return true;
		}else{
			return false;
		}
	}
	public static boolean isOverlap(Date leftStartDate, Date leftEndDate,Date rightStartDate, Date rightEndDate) {    
        return     
            ((leftStartDate.getTime() >= rightStartDate.getTime())     
                    && leftStartDate.getTime() < rightEndDate.getTime())    
            ||    
            ((leftStartDate.getTime() > rightStartDate.getTime())     
                    && leftStartDate.getTime() <= rightEndDate.getTime())    
            ||    
            ((rightStartDate.getTime() >= leftStartDate.getTime())     
                    && rightStartDate.getTime() < leftEndDate.getTime())    
            ||    
            ((rightStartDate.getTime() > leftStartDate.getTime())     
                    && rightStartDate.getTime() <= leftEndDate.getTime());    
                
    }  
	public static Date lastDayOfMonth(Date date) { 
		Calendar cal = Calendar.getInstance(); 
		cal.setTime(date); 
		cal.set(Calendar.DAY_OF_MONTH, 1); 
		cal.roll(Calendar.DAY_OF_MONTH, -1); 
		return cal.getTime(); 
	} 
	/* 获取当前时间之前或之后几小时 hour*/

    public static String getTimeByHour(int hour) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + hour);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
    }

    /*获取当前时间之前或之后几分钟 minute
    public static String getTimeByMinute(int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE, minute);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
    }
    */
    /*获取当前时间之前或之后几分钟 minute*/
    public static Date getTimeByMinute(Date nowDate,int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(nowDate);
        calendar.add(Calendar.MINUTE, minute);
        return calendar.getTime();
    }
    
    /*获取当前时间之前或之后几秒钟 second*/
    public static Date getTimeBySecond(Date nowDate,int second) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(nowDate);
        calendar.add(Calendar.SECOND, second);
        return calendar.getTime();
    }
    
    /**
     * 格式化从数据库中cast获取的日期格式,例如03 17 2016  5:03PM转为2016-03-17 17:03
     * @param value
     * @return
     */
    public static String getFormatHqlCastDate(Object value){
    	if(value==null)
    		return "";
    	String dateTime = value.toString();
    	if(StringUtil.isEmpty(dateTime))
    		return "";
    	String[] array = dateTime.split("~");
    	if(array.length==2){
    		return getFormatHqlCastDate(array[0])+"~"+getFormatHqlCastDate(array[1]);
    	}else{
    		array = dateTime.split(" ");
    		String[] resultArray = new String[3];
    		int i=0;
    		for(String s : array){
    			if(s.equals("")){
    				continue;
    			}
    			resultArray[i] = s;
    			i++;
    			if(i==resultArray.length){
    				break;
    			}
    		}
    		String time = array[array.length-1];
    		if(time.substring(time.length()-2).equals("PM")){
    			String[] a = time.split(":");
    			Integer hour = Integer.parseInt(a[0])+12;
    			String min = a[1];
    			time = hour +":"+min.substring(0,min.length()-2);
    		}else{
    			String[] a = time.split(":");
    			Integer hour = Integer.parseInt(a[0]);
    			String min = a[1];
    			time = (hour>9?hour.toString():"0"+hour) +":"+min.substring(0,min.length()-2);
    		}
    		return resultArray[2]+"-"+(resultArray[0].length()==1 ? "0"+resultArray[0]:resultArray[0])+"-"+(resultArray[1].length()==1 ? "0"+resultArray[1]:resultArray[1])+" "+time;
    	}
    }
    
    public static int checkDateFormatAndValite(String strDateTime,String showType) {
        //update it according to your requirement.
        SimpleDateFormat format = new SimpleDateFormat(showType);
        try {
            Date ndate = format.parse(strDateTime);
            String str = format.format(ndate);
            //System.out.println(ndate);
            //System.out.println(str);
            //System.out.println("strDateTime=" + strDateTime);
            //success
            if (str.equals(strDateTime))
                return 1;
            //datetime is not validate
            else
                return 0;
        } catch (Exception e) {
            //format error
            System.out.println(e.getMessage());
            return -1;
        }
    }
    //验证时间格式 yyyy-MM-ss
    public static boolean checkDateFormat(String strDateTime) {
        String eL= "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";        
        Pattern p = Pattern.compile(eL);
        Matcher m = p.matcher(strDateTime);
        boolean b = m.matches();
        if(b){
           //System.out.println("格式正确");
        	return true;
        }
        else{
           //System.out.println("格式错误");
        	return false;
        }
    }
    
    public static String getSearchDate(String date,boolean isEnd){
    	if(date.indexOf(":")==-1){
    		return date + (isEnd ? " 23:59:59" : " 0:0:0");
    	}
    	return date;
    }
	public static void main(String[] args) {
		//System.out.println(getMonthChange(null,-12,"yyyy-M-d H:m:s"));
		//System.out.println(formatDates(new Date()));
		//System.out.println(lastDayOfMonth(new Date()));
		//System.out.println(DateUtil.turnDateToString(getAfterDate(new Date(), 1), "yyyy-MM-dd HH:mm:ss"));
		//System.out.println(getTimeByMinute(new Date(),-30));
		//System.out.println(getFormatHqlCastDate("03 30 2016 11:20AM~03 30 2016 11:20AM"));
		System.out.println(DateUtil.getTimeDifferenceSencond(DateUtil.turnStringToDate("2021-03-25 03:00:00", "yyyy-MM-dd HH:mm:ss"), DateUtil.turnStringToDate("2021-03-25 02:00:00", "yyyy-MM-dd HH:mm:ss")));
		System.out.println(DateUtil.getTimeBySecond(new Date(), 8));
		System.out.println(new Date());
	}
}

